﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

using SpaceAdventureLib.Universe;
using TNCGameEngine.Content;

namespace SpaceAdventureLib.GamePlay
{
    [Serializable]
    public class Mission
    {

        #region "Properties"

        private Campaign campaign = null;
        public Campaign Campaign
        {
            get { return this.campaign; }
            set { this.campaign = value; }
        }

        public ContentManager Content
        {
            get { return this.campaign.ContentManager; }
        }

        public ContentLoader ContentLoader
        {
            get { return this.campaign.ContentLoader; }
        }

        private Space space = null;
        public Space Space
        {
            get { return this.space; }
            set { this.space = value; }
        }

        private Teams teams = null;
        public Teams Teams
        {
            get { return this.teams; }
            set { this.teams = value; }
        }

        private bool contentLoaded = false;
        public bool ContentLoaded
        {
            get { return this.contentLoaded; }
        }

        #endregion

        #region "Constructors"

        public Mission(Campaign game)
        {

            this.campaign = game;

            this.campaign.Missions.Add(this);
            
            this.space = new Space(this);
            this.teams = new Teams(this);

        }
                
        #endregion

        #region "General Methods"

        public void Initialize()
        {
            this.space.Initialize();
        }

        public List<AssetToLoad> GetAssetsToLoad()
        {
            return this.space.GetAssetsToLoad();
        }

        public void LoadContent(ContentLoader loader)
        {
            this.space.LoadContent(loader); 
        }

        public void UnloadContent(SharedContentManager content)
        {
            this.space.UnloadContent(content);
        }

        #endregion

        #region "Methods"

        public void Update(GameTime gameTime)
        {

            if (this.contentLoaded)
            {
                this.space.Update(gameTime);
            }
            else
            {
                this.space.LoadContent(this.campaign.ContentLoader);
                this.contentLoaded = true;
            }

        }

        public void Draw(GraphicsDevice g)
        {
            this.space.Draw(g);
        }

        #endregion


    }
}
